package com.real.operationalcontrols.企业列表;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.real.operationalcontrols.R;
import com.real.operationalcontrols.基类.BaseActivity;
import com.real.operationalcontrols.工具包.ChartQuxianWebView;
import com.real.operationalcontrols.工具包.WebViewLoadfinishListener;

import org.json.JSONArray;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Random;

import butterknife.BindView;
import butterknife.OnClick;

public class CompanyDetialActivity extends BaseActivity {

    @BindView(R.id.bar_back_btn)
    ImageView barBackBtn;
    @BindView(R.id.bar_title)
    TextView barTitle;
    @BindView(R.id.bar_check_btn)
    TextView barCheckBtn;
    @BindView(R.id.company_name)
    TextView companyName;
    @BindView(R.id.tv_time)
    TextView tvTime;
    @BindView(R.id.tv_cod)
    TextView tvCod;
    @BindView(R.id.tv_andan)
    TextView tvAndan;
    @BindView(R.id.web)
    ChartQuxianWebView web;
    @BindView(R.id.fen_btn)
    LinearLayout fenBtn;
    @BindView(R.id.hour_btn)
    LinearLayout hourBtn;
    @BindView(R.id.day_btn)
    LinearLayout dayBtn;
    @BindView(R.id.yue_btn)
    LinearLayout yueBtn;
    @BindView(R.id.year_btn)
    LinearLayout yearBtn;
    String id;
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //setContentView(R.layout.activity_company_detial);
    }

    @Override
    protected int getLayoutId() {
        return R.layout.activity_company_detial;
    }

    @Override
    protected void getData() {
        barTitle.setText("站点详情");
        barCheckBtn.setVisibility(View.VISIBLE);
        barCheckBtn.setText("智能抓拍");
        companyName.setText(getIntent().getStringExtra("name"));
        tvTime.setText(sdf.format(new Date()));
        tvCod.setText(String.format(String.format("%.2f", Math.random() * 10)));
        tvAndan.setText(String.format(String.format("%.2f", Math.random() * 10)));
        web.setListener(new WebViewLoadfinishListener() {
            @Override
            public void onWebViewLoadfinishListener() {
                initData();
            }
        });
    }

    private void initData() {
        JSONArray jsonArray = new JSONArray();
        JSONArray time = new JSONArray();
        for (int i = 0; i < 24; i++) {
            jsonArray.put(new Random().nextInt(100));
            time.put("" + i);
        }
        web.initData(jsonArray, time);
    }

    @OnClick({R.id.bar_back_btn, R.id.fen_btn, R.id.hour_btn, R.id.day_btn, R.id.yue_btn,
            R.id.year_btn,R.id.bar_check_btn})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.bar_back_btn:
                finish();
                break;
            case R.id.bar_check_btn:
                Intent img = new Intent(this, PhotoActivity.class);
                img.putExtra("id", id);
                startActivity(img);
                break;
            case R.id.fen_btn:
                Intent fen = new Intent(this, FenzhongHistoryActivity.class);
                fen.putExtra("id", id);
                startActivity(fen);
                break;
            case R.id.hour_btn:
                Intent hour = new Intent(this, HourHistoryActivity.class);
                hour.putExtra("id", id);
                startActivity(hour);
                break;
            case R.id.day_btn:
                Intent day = new Intent(this, DayHistoryActivity.class);
                day.putExtra("id", id);
                startActivity(day);
                break;
            case R.id.yue_btn:
                Intent waring = new Intent(this, WaringHistoryActivity.class);
                waring.putExtra("id", id);
                startActivity(waring);
                break;
            case R.id.year_btn:
                break;
        }
    }
}
